#include "junix.h"
#include <poll.h>

int main(int argc, char **argv)
{
	struct pollfd pds[2];

	pds[0].fd=open("XX",O_RDONLY);
	if(pds[0].fd==-1)
		err_sys("open");

	pds[1].fd=open("XX",O_RDONLY);
	if(pds[1].fd==-1)
		err_sys("open");

	pds[0].events=POLLIN;
	pds[1].events=POLLIN;

	while(1)
	{
		if(-1 == poll(pds,2,6) )
			err_sys("poll");

		int i;
		ssize_t sz;
		char buf[100];

		for(i=0;i<2;++i)
		{
			if( pds[i].revents )
			{
				if ( (sz=read(pds[i].fd, buf,99)) > 0)
				{
					buf[sz]='\0';
					fprintf(stdout,"%s\n",buf);
					fflush(stdout);
				}

				if(sz<0)
					err_sys("read");
			}
		}
	}

	return 0;
}

